/*
 *  Copyright (C) 2025 ameise <ameise.wang@gmail.com> - All Rights Reserved
 *
 *  This file is part of e3utils.
 *
 *  e3utils is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  e3utils is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with e3utils. If not, see <https://www.gnu.org/licenses/>.
 */

package load_balancer

import (
	"gitee.com/ameise84/e3ds/heap/compare"
)

type contextWrap[T Context] struct {
	ctx    T
	weight int //权重值越大,优先级越低.最大值为maxInt,最小值为0
}

func (i *contextWrap[T]) UniqueID() uint64 {
	return i.ctx.LoadBalancerID()
}

func (i *contextWrap[T]) Compare(other *contextWrap[T]) compare.Result {
	d := i.weight - other.weight
	if d < 0 {
		return compare.Smaller
	}
	if d > 0 {
		return compare.Larger
	}
	return compare.Equal
}
